import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 			= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
const enabledData = [{ name:'审核未通过', value:-1 },{ name:'待完善', value:0 },{ name:'待审核', value:1 },{ name:'审核通过', value:2 }]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		// 所有的搜索医院，项目用下拉带搜索 20211012 耿琰
		forms : [
			{ label: '状态',			name: 'status',	type: 'select', data:enabledData},
			{ label: '医院名称',  	name: 'hospital_id', type:'select',  onValue:({ rows }) => {
				this.model.hosp_name = rows ? rows.name : ''
      } },
			{ label: '条码号',		name: 'spec_code', },
			{ label: '病人姓名',		name: 'patient_name',},
			{ label: '日期', 		names: ['start_date','end_date'], type:'date-range' },
		],
		
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		
		if(window.isInit){
		  this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = async () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 医院
			$fn.setRow( forms, 'hospital_id', await f.getCache({ api:'hospital' }) )
		})
	}
	 
	// paging
	fetch = () => $fn.fetch.call(this,'spec-case-info/logisticslists')
	
	// 表格
	cols = [
		{ title: '标本条码',			dataIndex: 'spec_code', 		width:150 },
		{ title: '医院名称', 		dataIndex: 'hosp_name', 		width:200 },
		{ title: '送检科室', 		dataIndex: 'department_name', 	width:150 },
		{ title: '送检医生', 		dataIndex: 'doctor', 			width:150 },
		{ title: '病人姓名',			dataIndex: 'patient_name', 		...$fn.table.name },
		{ title: '性别', 			dataIndex: 'sex', 				...$fn.table.sex,render: text => +text ===45701 ? '男' : '女'},
		{ title: '年龄', 			dataIndex: 'newAge', 			...$fn.table.age },
		{ title: '送检时间',			dataIndex: 'check_time',	 	...$fn.table.time},
		{ title: '状态', 			dataIndex: 'status', 			...$fn.table.status,  render: text=>$fn.getState(enabledData,text) },
		TableControls.controls.call(this,{ width: 150 })
	]
	// 表格操作按钮
	table_controls = (text,{ uuid, spec_code }) => {
		return [
			TableControls.pushTo.call(this, '详细信息', `check-report?spec_code=${spec_code}&uuid=${uuid}`),
		]
	}
	
	render(){
		return (
			<>
				<Page title='基础信息' >
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { isInit: window.isInit }) }
				</Page>
				
			</>
		)
	}
}

export default Index